package com.lxp.order.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lxp.order.domain.TOrder;
import com.lxp.order.service.TOrderService;
import com.lxp.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author lxp
 * @since 2022-02-03
 */
@RestController
@RequestMapping("/order/tOrder")
public class TOrderController {
    @Autowired
    private TOrderService service;
    //生成订单
    @GetMapping("/createOrder/{courseId}")
    public R createOrder(HttpServletRequest request, @PathVariable String courseId){
        String orderId=service.createOrder(request,courseId);
        return R.ok().data("orderId",orderId);
    }

    //根据订单id,获取订单
    @GetMapping("/getOrder/{orderId}")
    public R getOrder( @PathVariable String orderId){
        TOrder order = service.getOne(new QueryWrapper<TOrder>()
                .eq("order_no",orderId));
        return R.ok().data("order",order);
    }
    //查询用户是否购买了课程
    @GetMapping("/checkUserIsBuy/{courseId}")
    public R checkUserIsBuy(HttpServletRequest request,@PathVariable String courseId){
        boolean isBuy=service.checkUserIsBuy(request,courseId);
        return R.ok().data("isBuy",isBuy);
    }
}

